﻿using Prism.Events;
using Prism.Mvvm;
using RoboAssembleX.Application.ActionJbo;
using RoboAssembleX.Application.AddBoard1;
using RoboAssembleX.Application.AddGlass;
using RoboAssembleX.Application.AddGlass1;
using RoboAssembleX.Application.AddNeedle1;
using RoboAssembleX.Application.AddNeedle2;
using RoboAssembleX.Application.Common;
using RoboAssembleX.Application.Robot;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace RoboAssembleX.Application.ActionJobs
{
    public class ActionJob06 : BindableBase,IActionJob
    {
        private readonly IEventAggregator eventAggregator;
        private readonly RoboModel roboModel;
        private readonly RoboService roboService;
        private readonly AddNeedle2Model addNeedle2Model;
        private readonly AutoRunModel autoRunModel;

        public ActionJob06(IEventAggregator eventAggregator,RoboModel roboModel, 
            RoboService roboService, AddNeedle2Model addNeedle2Model, AutoRunModel autoRunModel)
        {
            this.eventAggregator = eventAggregator;
            this.roboModel = roboModel;
            this.roboService = roboService;
            this.addNeedle2Model = addNeedle2Model;
            this.autoRunModel = autoRunModel;
        }
        private string name = "引线二到下料"; public string Name { get => name; }
        private bool running; public bool Running { get => running; set { running = value; RaisePropertyChanged(); } }
        private bool enable = true; public bool Enable { get => enable;  set { enable = value; RaisePropertyChanged(); } }
        private int priority = 0; public int Priority { get => priority; set { priority = value; RaisePropertyChanged(); } }



        public bool IsReady
        {
            get
            {
                // 引线允许取料  引线料位有料
                return addNeedle2Model.AllowRemove 
                     && addNeedle2Model.PosUsed;
            }
        }

        public async Task RunActionAsync()
        {
            Running = true;
            eventAggregator.GetEvent<MessageEvent>().Publish(new MessageEventArgs("启动机械臂动作6!", 1));
            await  roboService.Action6Async();
            while(roboModel.DO6)
            {
               await  Task.Delay(100);
            }
            autoRunModel.ProdQty += 1;
            await Task.Delay(100);
            Running = false;
        }
    }
}
